package com.im.service.friendship.controller;

import com.im.common.model.RestResponse;
import com.im.service.friendship.model.req.ApproverFriendRequestReq;
import com.im.service.friendship.model.req.GetFriendShipRequestReq;
import com.im.service.friendship.model.req.ReadFriendShipRequestReq;
import com.im.service.friendship.service.ImFriendShipRequestService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

@Api(tags = "好友请求控制器")
@RestController
@RequestMapping("v1/friendshipRequest")
public class ImFriendShipRequestController {

    @Autowired
    ImFriendShipRequestService imFriendShipRequestService;

    @ApiOperation("批准交友请求")
    @RequestMapping(value = "/approveFriendRequest", method = RequestMethod.POST)
    public RestResponse approveFriendRequest(@RequestBody @Validated ApproverFriendRequestReq req, Integer appId, String identifier) {
        req.setAppId(appId);
        req.setOperator(identifier);
        imFriendShipRequestService.approverFriendRequest(req);
        return RestResponse.success();
    }

    @ApiOperation("获取好友请求")
    @RequestMapping(value = "/getFriendRequest", method = RequestMethod.POST)
    public RestResponse getFriendRequest(@RequestBody @Validated GetFriendShipRequestReq req, Integer appId) {
        req.setAppId(appId);
        imFriendShipRequestService.getFriendRequest(req.getFromId(), req.getAppId());
        return RestResponse.success();
    }

    @ApiOperation("读取FriendShip请求")
    @RequestMapping(value = "/readFriendShipRequestReq", method = RequestMethod.POST)
    public RestResponse readFriendShipRequestReq(@RequestBody @Validated ReadFriendShipRequestReq req, Integer appId) {
        req.setAppId(appId);
        imFriendShipRequestService.readFriendShipRequestReq(req);
        return RestResponse.success();
    }


}
